{% load staticfiles %}
<div class="breadcrumbs ace-save-state" id="breadcrumbs">
	<ul class="breadcrumb">
		<li>
			<i class="ace-icon fa fa-bar-chart-o"></i>
			<a href="javascript:void(0)">数据统计</a>
		</li>
		<li class="active">扫码记录</li>
	</ul><!-- /.breadcrumb -->

	<div class="nav-search" id="nav-search">

	</div><!-- /.nav-search -->
</div>

<div class="page-content">

	<div class="row" id="page_scan_log_list">
		<div class="widget-box widget-color-blue">
			<div class="widget-header">
				<h5 class="widget-title">扫码记录</h5>

				<div class="widget-toolbar">
					<a href="#" data-action="collapse">
						<i class="1 ace-icon fa fa-chevron-up bigger-125"></i>
					</a>
				</div>

			</div>

			<div class="widget-body">

				<div class="widget-main">
					<div class="row">
						<div class="col-xs-12">
							<form style="padding: 0px 0px 10px 0px" id="scan_log_list_form">
								<input type="text" class="form-control query-input" name="product_name" placeholder="产品">
								<input type="text" class="form-control query-input" name="scan_province" placeholder="扫码省份">
								<input type="text" class="form-control query-input" name="publish_province" placeholder="发布省份">
								<input type="text" class="form-control query-input" name="scan_start_time" placeholder="开始时间">
								<input type="text" class="form-control query-input" name="scan_end_time" placeholder="结束时间">
								<input type="button" class="btn btn-sm btn-primary" style="display: inline-block" value="查询" onclick="reloadScanLogList()">
							</form>
						</div>

						<div class="col-xs-12">
							<!-- PAGE CONTENT BEGINS -->
							<table id="scan-log-grid-table"></table>
							<div id="scan-log-grid-pager"></div>
							<!-- PAGE CONTENT ENDS -->
						</div><!-- /.col -->
					</div>
				</div>

			</div>
		</div>
	</div>

	<div class="row" id="page_scan_log_detail">


	</div>
</div><!-- /.page-content -->

<script type="text/javascript">

	scan_log_page_init();

	function scan_log_page_init() {

		var grid_selector = "#scan-log-grid-table";
		var pager_selector = "#scan-log-grid-pager";

		// 初始化
		var grid_config ={{ grid_config|safe }};

		function style_edit_form_field(form) {

		}

		// 操作列
		JqGridHelp.updateColModel(grid_config, "myac",
			{
				formatoptions: {
					keys: true,

					editbutton: true,
					editformbutton: false,
					onEdit: null,
					onSuccess: null,
					afterSave: null,
					onError: null,
					afterRestore: null,
					extraparam: {my: 'my'},
					editOptions: {
						recreateForm: true,
						beforeShowForm: JqGridHelp.beforeEditCallback
					},

					delbutton: true,
					delOptions: {
						recreateForm: true,
						beforeShowForm: JqGridHelp.beforeDeleteCallback
					}
				}
			}
		);

		function formatLink(cellValue, options, rowObject) {
			return '<a href="javascript:void(0)" onclick="BrandViewer.loadBrandDetail(' + rowObject.id + ')" >' + cellValue + '</a>';
		}

		function formatMyAc(cellValue, options, rowObject, state) {
			var detail = '<div title="查看详情" style="float:left;cursor:pointer;" ' +
				'class="ui-pg-div ui-inline-edit"' +
				'onclick="BrandViewer.loadBrandDetail(' + rowObject.id + ');" ' +
				'onmouseover="jQuery(this).addClass(\'ui-state-hover\');" ' +
				'onmouseout="jQuery(this).removeClass(\'ui-state-hover\');">' +
				'<span class="ui-icon ui-icon-pencil"></span>' +
				'</div>';

			return '<div style="margin-left:8px;">' + detail + '</div>'
		}

{#		JqGridHelp.updateColModel(grid_config, "name_zh", {formatter: formatLink});#}
{#		JqGridHelp.updateColModel(grid_config, "logo", {formatter: formatLogo});#}
{#		JqGridHelp.updateColModel(grid_config, "check_status", {formatter: formatCheckStatus});#}
		JqGridHelp.updateColModel(grid_config, "myac", {formatter: formatMyAc});

		var jqGridHelp = JqGridHelp.createNew(grid_selector, pager_selector, grid_config, style_edit_form_field);

		// 隐藏标题
		$(".ui-jqgrid-titlebar").hide();
	}

	function reloadScanLogList() {
		var filters = {"groupOp": "AND", "rules": []};
		var rules = filters.rules;
		var args = formserializeJson("scan_log_list_form");
		for (var name in args) {
			var value = args[name];
			if (value) {
				rules.push({field: name, op: "cn", data: value});
			}
		}

		var postData = $("#scan-log-grid-table").jqGrid("getGridParam", "postData");
		$.extend(postData, {filters: JSON.stringify(filters)});
		$("#scan-log-grid-table").jqGrid("setGridParam", {search: true}).trigger("reloadGrid", [{page: 1}]);  //重载JQGrid
	}

</script>